package examples.jsf;

/**
 * @author Bill
 * @version 2013-05-29
 */
public class FactoryFinder {

    public static <T> T getFactory(String factoryName) {
        ClassLoader cl = getClassLoader();
        FactoryManager factoryManager = new FactoryManager(cl);

        if (factoryName.equals("")) {
            return (T)factoryManager.getFactory(factoryName);
        }
        return null;
    }

    private static ClassLoader getClassLoader() throws FacesException {

        // J2EE 1.3 (and later) containers are required to make the
        // web application class loader visible through the context
        // class loader of the current thread.
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        if (cl == null) {
            throw new FacesException("getContextClassLoader");
        }
        return (cl);

    }

    static class FactoryManager {

        ClassLoader cl = null;

        FactoryManager(ClassLoader cl) {
            this.cl = cl;
        }

        public Object getFactory(String factoryName) {
            return null;
        }
    }

}
